// src/oneof_ex.cc

#include <iostream>
#include "protos/oneof_ex.pb.h"

int main() {
    tutorial::MyMessage msg;
    msg.set_name("Alice");
    msg.set_id(42);  // 设置 oneof 字段

    // 判断当前设置的是哪个 oneof 字段
    switch (msg.content_case()) {
        case tutorial::MyMessage::kId:
            std::cout << "ID = " << msg.id() << std::endl;
            break;
        case tutorial::MyMessage::kJackEmail:
            std::cout << "Email = " << msg.jack__email_() << std::endl;
            break;
        case tutorial::MyMessage::kNested:
            std::cout << "Nested.detail = " << msg.nested().detail() << std::endl;
            break;
        case tutorial::MyMessage::CONTENT_NOT_SET:
            std::cout << "No oneof field set.\n";
            break;
    }

    // 清除 oneof 字段
    msg.clear_content();
    std::cout << "After clear, content_case = " << msg.content_case() << std::endl;

    return 0;
}
